function delete(ti)
% transimg::delete  - delete an image from global storage

% Version:  v0.8a
% Build:    9112017
% Date:     Nov-20 2009, 5:13 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% global variables for storage
global tiobj ...
       tiobjlup;
   
% check arguments
lup = find(tiobjlup == ti.L);
if numel(lup) ~= 1
    error( ...
        'transimg:ObjectRemoved', ...
        'Object already removed from global storage.' ...
    );
end

% handle exists
if ~isempty(tiobj(lup).Handle) && ...
    ishandle(tiobj(lup).Handle)
    try
        x = get(tiobj(lup).Handle, 'Parent');
        f = get(x, 'Parent');
        n = get(f, 'Name');
        if strcmp(n(1:9), 'transimg:')
            delete(f);
        end
    catch
        % do nothing
    end
end

% remove now
tiobj(lup) = [];
tiobjlup(lup) = [];
